import router from "../router/index";

const token = localStorage.getItem("token");
// 根据路由配置文件的参数来确定路由的跳转
router.beforeEach((to, from, next) => {
  if (to.matched.some((record) => record.meta.requireAuth)) {
    // 判断该路由是否需要登录权限
    console.log("------------" + token);
    // 判断当前的token是否存在,若不存在就是直接跳转到login页面
    if (!token === null && token === undefined) {
      next({
        path: "/login",
        query: {
          redirect: to.fullPath,
        },
      });
    } else {
      next();
    }
  } else {
    next();
  }
});
